// 1： 导入路由
//import {createRouter, createWebHashHistory} from 'vue-router'
import {createRouter, createWebHistory} from 'vue-router'
//3: 创建路由器对象，将模板全部进行路由匹配和注册
const router = createRouter({
    // HASH访问模式， http://localhost:8080/#news
    //history: createWebHashHistory(),
    // URL访问模式，http://localhost:8080/news
    history: createWebHistory(),
    routes: [
        // 设置欢迎页面，就path设置成 "/"即可
        {path: '/', name:"index",meta: {title: "首页"}, component: () => import("@/views/Home")},
        {path: '/news', name:"news",meta: {title: "新闻"}, component: () => import("@/views/News")},
        {path: '/book', name:"book",meta: {title: "书籍"}, component: () => import("@/views/Book"),children:[
            {path: '/book/:id',name:"bookdetail1",meta: {title: "书籍明细1"}, component: () => import("@/views/BookDetail")},
            {path: '/book2',name:"bookdetail2",meta: {title: "书籍明细2"}, component: () => import("@/views/BookDetail")},
            {path: '/bookdetail/:id/:title',name:"bookdetail3",meta: {title: "书籍明细2"},
                component: () => import("@/views/BookDetail2"),props:true}
        ]},
        {path: '/course', name:"course",meta: {title: "课程"}, component: () => import("@/views/Course")},
        {path: '/video', name:"video",meta: {title: "视频"}, components:  {Video:import("@/views/Video")}},
        {path: '/error', name:"error",meta: {title: "错误"}, components:  {Video:import("@/views/Error")}},
        {path: '/toerror', name:"toerror",redirect:"/error"},


        // 用户管理
        {
            path: '/user', name:"user",meta: {title: "用户管理"}, component: () => import("@/views/user/UserMain"),
            children:[
                {path: '/user',name:"userlist",meta: {title: "用户列表"}, component: () => import("@/views/user/UserList")},
                {path: '/user/add',name:"useradd",meta: {title: "用户添加"}, components: {Add:() => import("@/views/user/UserAdd")}},
            ]
        },

        // 登录

        {path:"/login",name:"login",meta:{title:"登录"},component:()=>import('@/views/Login')}


    ]
});



//
// router.beforeEach((to) => {
//     // 1: 判断path是否匹配上
//     if(to.matched.length == 0){
//         return {
//             path:"/toerror",
//             query:{bk:to.fullPath}
//         };
//     }
//     return true;
// });





router.afterEach(to => {
    document.title = to.meta.title;
})

// 4: 导出模板router模块即可
export default router